package top.korori.common.exception;

import lombok.AllArgsConstructor;
import lombok.Getter;
import top.korori.common.enums.StatusCode;

/**
 * 业务异常
 *
 */
@Getter
@AllArgsConstructor
public class BizException extends RuntimeException {

    /**
     * 错误码
     */
    private Integer code = 500;

    /**
     * 错误信息
     */
    private String msg;

    public BizException(String msg) {
        super(msg);
        this.msg = msg;
    }

    public BizException(StatusCode statusCode) {
        super(statusCode.getDesc());
        this.msg = statusCode.getDesc();
        this.code = statusCode.getCode();
    }

    public static void cast(String msg) {
        throw new BizException(msg);
    }


    public static void cast(StatusCode statusCode){
        throw new BizException(statusCode);
    }


}
